google.load("visualization", "1", {'packages':["corechart"]});
google.load('visualization', '1', {'packages': ['piechart']});


// final function that builds the chart from the json object
function drawMarketRepartitionChart(represp0) 
{
    var represp = eval('(' + represp0.responseText + ')'); 
	var repdata = new google.visualization.DataTable();
	repdata.addColumn('string', 'Asset');
	repdata.addColumn('number', 'Repartition');
	repdata.addRows(represp.viewList.length);
    for (var i = 0; i < represp.viewList.length; i++)
    {
        repdata.setValue(i, 0, represp.viewList[i].assetName );
        repdata.setValue(i, 1, represp.viewList[i].view);
    }

    var repchart = new google.visualization.PieChart(document.getElementById('repartitionMarketChart_div'));
	repchart.draw(repdata, {width: 300, height: 230, title: 'Market Expectations (Click to see values)'});
};
var updateMarketRepartitionChart = function() 
{
    var args = { type:"get", url:"/json/getMarketView/", complete:drawMarketRepartitionChart };
    $.ajax(args);
    return false;
};

$(document).ready( function() 
{
    updateMarketRepartitionChart();
});
    
//thi graph does not need to bee updated since it only depend on the player
//setInterval( "updateRepartitionChart()", 10000 );
